package org.andhy.formeasy.core;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Set;


public class Validater {
	private List<ValidateItem> vis = new ArrayList<ValidateItem>();
	
	public Result validate(Map<String,Object> params){
		Result result = new Result();
		if(params == null){
			return result;
		}
		for(ValidateItem vi : vis){
			String paramName = vi.getName();
			Object value = params.get(paramName);
			Set<String> msgHold = vi.validate(value);
			if(!msgHold.isEmpty()){
				result.setSuccess(false);
				result.addMesaageSet(paramName, msgHold);
			}
		}
		return result;
	}
	public void addItem(ValidateItem item){
		vis.add(item);
	}
}